<!DOCTYPE html>
<html>
    <head>
        <title>AGM销售注册</title>
        <link rel="stylesheet" href="/static/weui.min.css">
        <link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <style>
            .page, body{background-color: #fbf9fe}
            .page_title{color:#225fba}
            .hd{text-align:center}
            .weui_label{width:4em;}
            .bd{padding-bottom:30px;}
        </style>
    </head>
    <body>
        {% if ifseller in [0, 1] %}
        <div class="hd">
            <h1 class="page_title">AGM销售注册</h1> 
        </div>
        <div class="bd">
            <form id="register_form">
                <div class="weui_cells_title">注册资料信息填写</div>
                <div class="weui_cells weui_cells_form">
                    <div class="weui_cell">
                        <div class="weui_cell_hd"><label class="weui_label">商场代码</label></div>
                        <div class="weui_cell_bd weui_cell_primary">
                            <input name="shopcode" class="weui_input" placeholder="请输入商场代码" value="{{seller.get('shopcode') or ""}}" required="required" >
                        </div>
                    </div> 
                    {#
                    <div class="weui_cell">
                        <div class="weui_cell_hd"><label class="weui_label">商场名称</label></div>
                        <div class="weui_cell_bd weui_cell_primary">
                            <input name="shopname" class="weui_input" placeholder="格式：湖南长沙永旺百货" value="{{seller.get('shopname') or ""}}" required="required">
                        </div>
                    </div>
                    <div class="weui_cell">
                        <div class="weui_cell_hd"><label class="weui_label">商场地址</label></div>
                        <div class="weui_cell_bd weui_cell_primary">
                            <input name="shopaddr" class="weui_input" placeholder="省 市 区 路名门牌或路口交界" value="{{seller.get('shopaddr') or ""}}" required="required" >
                        </div>
                    </div> #}
                    <div class="weui_cell">
                        <div class="weui_cell_hd"><label class="weui_label">经销代码</label></div>
                        <div class="weui_cell_bd weui_cell_primary">
                            <input name="dealercode" class="weui_input" placeholder="输入所属的经销商代号" value="{{seller.get('dealercode') or ""}}" required="required" >
                        </div>
                    </div>                     
                    <div class="weui_cell">
                        <div class="weui_cell_hd"><label class="weui_label">微信ID</label></div>
                        <div class="weui_cell_bd weui_cell_primary">
                            <input name="wxid" class="weui_input" placeholder="请输入微信号ID" value="{{seller.get('wxid') or ""}}" required="required" >
                        </div>
                    </div>
                    <div class="weui_cell">
                        <div class="weui_cell_hd"><label class="weui_label">手机</label></div>
                        <div class="weui_cell_bd weui_cell_primary">
                            <input name="phone" class="weui_input" type="tel" placeholder="请输入可联系的手机号码" value="{{seller.get('phone') or "" or ""}}" required="required">
                        </div>
                    </div>                    
                </div>
                <div class="weui_btn_area">
                    <button class="weui_btn weui_btn_primary" id="uploadbtn" type="submit">{% if ifseller == 1 %}重新提交{% else %}确定{% endif %}</button>
                </div>
            </form>
        </div>
        <div class="weui_dialog_confirm" id="dialog1" style="display:none">
            <div class="weui_mask"></div>
            <div class="weui_dialog">
                <div class="weui_dialog_hd"><strong class="weui_dialog_title">弹窗标题</strong></div>
                <div class="weui_dialog_bd">自定义弹窗内容，居左对齐显示，告知需要确认的信息等</div>
                <div class="weui_dialog_ft">
                    <a class="weui_btn_dialog default">取消</a>
                    <a class="weui_btn_dialog primary">确定</a>
                </div>
            </div>
        </div>        
        <div class="weui_dialog_alert" id="dialog2" style="display:none">
            <div class="weui_mask"></div>
            <div class="weui_dialog">
                <div class="weui_dialog_hd"><strong class="weui_dialog_title">弹窗标题</strong></div>
                <div class="weui_dialog_bd">弹窗内容，告知当前页面信息等</div>
                <div class="weui_dialog_ft">
                    <a class="weui_btn_dialog primary">确定</a>
                </div>
            </div>
        </div>
        <div id="loadingToast" class="weui_loading_toast" style="display:none;">
            <div class="weui_mask_transparent"></div>
            <div class="weui_toast">
                <div class="weui_loading">
                    <!-- :) -->
                    <div class="weui_loading_leaf weui_loading_leaf_0"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_1"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_2"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_3"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_4"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_5"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_6"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_7"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_8"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_9"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_10"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_11"></div>
                </div>
                <p class="weui_toast_content">数据加载中</p>
            </div>
        </div> 
        <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
        <script src="/static/jquery.maskedinput.min.js"></script>        
        <script>
            dialog2 = function(title, content, sucfunc){
                var self = $('#dialog2')
                self.find('.weui_dialog_title').text(title)
                self.find('.weui_dialog_bd').html(content)
                var clickfunc = sucfunc?sucfunc:function(){self.hide();}
                self.find('.weui_btn_dialog.primary').click(clickfunc)
                self.show()
            }
            $(document).on('click', '.weui_btn_disabled', function(){
                return false;
            })
			validform = function(form){
				var valid = true
				form.find('input[required]').each(function(){
					if(this.value==""){
						alert('注意：项目输入不全，请重新核对')
						this.focus()
						valid = false
						return false
					}
				})
				return valid
			}
            $('#register_form').submit(function(e){
                e.preventDefault();
				var self = $(this)
				if(!validform(self)){
					return false
				}
                myloadingshow('提交中..')
                $('#uploadbtn').addClass('weui_btn_disabled')
                $.post('manage?action=sellregister', $(this).serialize()).done(function(data){
                    $('#loadingToast').hide()
                    $('#uploadbtn').removeClass('weui_btn_disabled')
                    console.info(data)
                    if(data=='sellregistersuccess'){
                        dialog2('销售注册提交成功', '<i class="weui_icon_msg weui_icon_success"></i><div>您的销售注册资料信息已经提交成功<br/>请耐心等待审核结果</div>')
                    }else if(data=='alreadypost'){
                        dialog2('温馨提示:重复提交', '<i class="weui_icon_msg weui_icon_info"></i><div>你已经提交过资料<br/>请勿重复操作</div>')
                    }else if(data=='nodealercode'){
                        $('input[name=dealercode]').select()
                        $('input[name=dealercode]').focus()
                        dialog2('经销商代码输入有误', '<i class="weui_icon_msg weui_icon_warn"></i><div>您的经销商代码有误<br/>请重新输入或询问管理员</div>')
                    }else if(data=='noshopcode'){
                        $('input[name=noshopcode]').select()
                        $('input[name=noshopcode]').focus()
                        dialog2('商场代码输入有误', '<i class="weui_icon_msg weui_icon_warn"></i><div>您的商场代码有误<br/>请重新输入或询问管理员</div>')
                    }                    
                })
            })
            myloadingshow = function(title){
                var toast = $('#loadingToast')
                toast.find('.weui_toast_content').text(title)
                toast.show()
            }
            $("[name=dealercode]").mask('9-999-99-999', {'completed': function(){
                console.info(this.val())
                //$('#postfwcodebtn').removeClass('weui_btn_disabled')
            }}) 
            $("[name=shopcode]").mask('S-99-99-999', {'completed': function(){
                console.info(this.val())
                //$('#postfwcodebtn').removeClass('weui_btn_disabled')
            }})             
        </script> 
        {#
        {% elif ifseller == 1 %}
        <div class="weui_msg">
            <div class="weui_icon_area"><i class="weui_icon_msg weui_icon_waiting weui_icon_msg"></i></div>
            <div class="weui_text_area">
                <h2 class="weui_msg_title">正在审核中</h2>
                <p class="weui_msg_desc">您已提交注册申请<br/>您的申请正在审核中<br/>无需再申请</p>
            </div>
            <div class="weui_opr_area">
                <p class="weui_btn_area">
                    <a href="/" class="weui_btn weui_btn_primary">确定</a>
                </p>
            </div>
        </div> #}        
        {% else %} 
        <div class="weui_msg">
            <div class="weui_icon_area"><i class="weui_icon_msg weui_icon_warn weui_icon_msg"></i></div>
            <div class="weui_text_area">
                <h2 class="weui_msg_title">微信未登录</h2>
                <p class="weui_msg_desc">本页面需要登录可见<br/>请先按确定微信登录后，再进入本页面</p>
            </div>
            <div class="weui_opr_area">
                <p class="weui_btn_area">
                    <a href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx147a7583c9622a1b&redirect_uri=http%3A//m.top-racer.com/auth2%3Fgoto%3Dsellregister&response_type=code&scope=snsapi_base#wechat_redirect" class="weui_btn weui_btn_primary">确定</a>
                    <a href="/" class="weui_btn weui_btn_default">取消</a>
                </p>
            </div>
        </div> 
        {% endif %}
    </body>    
<html>